package com.abc.robot01.vivemodel

import android.util.Log
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.abc.robot01.retrofit.RetrofitService
import com.abc.robot01.retrofit.bean.Condition7
import com.abc.robot01.retrofit.bean.Condition70
import com.abc.robot01.retrofit.bean.FetchDataRequest9
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch


class SystemMessageFragmentViewModel : ViewModel() {
    val TAG = "SystemMessageFragmentViewModel"
    val customerName = mutableStateOf("")
    val totalAmount = mutableStateOf("15.08")
    val count = mutableStateOf("0")
    val customerPhone = mutableStateOf("")

    //客户列表
    private val _customerList = MutableStateFlow<List<RetrofitService.RenderItem>>(emptyList())
    val customerList: StateFlow<List<RetrofitService.RenderItem>> = _customerList

    fun load() {
        viewModelScope.launch {
            val res = RetrofitService.instance.getListRenderTask(
                accessToken = Robot.accessToken,
                companyId = Robot.companyId,
                request = FetchDataRequest9(
                    condition = Condition70(
                    )
                )
            )
            Log.e(TAG, "系统渲染记录:${res.data.list!!.size}")
            Log.e(TAG, "系统渲染记录:$res")
            if (res.code == 200) {
                _customerList.value = res.data.list
                count.value = res.data.list.size.toString()


            }
        }
    }
}
